# encoding = utf-8
class UsersController < ApplicationController
  
  before_filter :authenticate_admin!, :only => [:list, :delete]
  before_filter :authenticate_user!, :only => [:show]

  def show
    redirect_to :action => 'info'
  end

  def info
    @user = current_user
  end
  
  def manage_info
    if current_user.info.nil?
      redirect_to '/infos/new'
    else
      redirect_to "/infos/edit"
    end
  end

  def deals
    @deals = current_user.deals.order('created_at desc').paginate :page => params[:page], :per_page => PAGE_SIZE
  end

  def vouchers
    @vouchers = current_user.vouchers.order('money desc').paginate :page => params[:page], :per_page => PAGE_SIZE
  end
  
  def feedbacks
    @feedbacks = current_user.feedbacks.order('created_at desc').paginate :page => params[:page], :per_page => PAGE_SIZE
  end
  
  #  == admin ====================================================================

  def list
    @users = User.order('created_at desc').paginate :page => params[:page], :per_page => PAGE_SIZE
    render :layout => 'admins'
  end

  def delete
    user = User.find(params[:id])
    if user.destroy
      flash[:success] = '用户删除成功'
    end
    redirect_to :action => "list"
  end
  
end
